package com.hustzp.com.xichuangzhu.poetry.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.custom.vg.list.CustomAdapter;
import com.hustzp.com.xichuangzhu.R;
import com.hustzp.com.xichuangzhu.poetry.model.CollectionWorks;

import java.util.List;

/**
 * Copyright (C) 2015 The huimai mobile client Project
 * All right reserved.
 *
 * @author: wuzhimin@huimai365.com
 * @date: 2016/5/28 0:06
 * @Description:诗词分类适配器
 */
public class CollectionWorkCatagoryAdapter extends CustomAdapter {
    private Context context;
    private List<CollectionWorks> collectionses;

    public CollectionWorkCatagoryAdapter(Context context, List<CollectionWorks> collectionses) {
        this.context = context;
        this.collectionses = collectionses;
    }

    @Override
    public int getCount() {
        return collectionses.size();
    }

    @Override
    public CollectionWorks getItem(int position) {
        return collectionses.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(context,
                    R.layout.activity_poetry_catagory_item, null);
            holder.initView(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        bindViews(position, holder);
        return convertView;
    }

    private void bindViews(int position, ViewHolder holder) {
        CollectionWorks collections = getItem(position);
        holder.tv_catagory_name.setText(collections.getCollection());
    }

    class ViewHolder {
        TextView tv_catagory_name;

        public void initView(View view) {
            tv_catagory_name = (TextView) view
                    .findViewById(R.id.tvCatagoryName);
        }
    }
}
